package org.pzy.crazymakecircle;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author: DRevelation
 * @Date: 2022/5/27 9:32
 */
@Slf4j
public class NettyDiscardHandler extends ChannelInboundHandlerAdapter {

    public NettyDiscardHandler() {
        super();
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        log.info("======channel_active......");
        super.channelActive(ctx);
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf in = (ByteBuf) msg;
        log.info("======channel_read......接收消息，丢弃如下: ");
        while (in.isReadable()) {
            System.out.print(in.readByte());
        }
        System.out.println();
        super.channelRead(ctx, msg);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        super.exceptionCaught(ctx, cause);
    }
}
